package com.burst.reptile.modular.monitor.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.burst.reptile.common.utils.poi.ExcelUtil;
import com.burst.reptile.framework.aspectj.lang.annotation.Log;
import com.burst.reptile.framework.aspectj.lang.enums.BusinessType;
import com.burst.reptile.framework.web.controller.BaseController;
import com.burst.reptile.framework.web.result.LayuiResult;
import com.burst.reptile.framework.web.result.Result;
import com.burst.reptile.modular.monitor.entity.SysLogininfor;
import com.burst.reptile.modular.monitor.service.ISysLogininforService;

import lombok.RequiredArgsConstructor;

/**
 * <p>
 * 系统访问记录 前端控制器
 * </p>
 *
 * @author wujin
 * @since 2020-05-22
 */
@RestController
@RequestMapping("/monitor/logininfor")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class SysLogininforController extends BaseController {

	private final ISysLogininforService logininforService;

	/**
	 * 登录日志列表
	 * @param logininfor
	 * @return
	 */
	@PreAuthorize("@ss.hasPermi('monitor:logininfor:list')")
	@GetMapping("/list")
	public LayuiResult<Object> list(SysLogininfor logininfor) {
		Page<SysLogininfor> page = startPage();
		Page<SysLogininfor> list = logininforService.selectPageLogininforList(page, logininfor);
		return LayuiResult.success(list.getTotal(), list.getRecords());
	}

	/**
	 * 导出登录日志
	 * @param logininfor
	 * @return
	 */
	@Log(title = "登陆日志", businessType = BusinessType.EXPORT)
	@PreAuthorize("@ss.hasPermi('monitor:logininfor:export')")
	@GetMapping("/export")
	public Result<Object> export(SysLogininfor logininfor) {
		List<SysLogininfor> list = logininforService.selectLogininforList(logininfor);
		ExcelUtil<SysLogininfor> util = new ExcelUtil<SysLogininfor>(SysLogininfor.class);
		return util.exportExcel(list, "登陆日志");
	}

	/**
	 * 删除登录日志
	 * @param infoIds
	 * @return
	 */
	@PreAuthorize("@ss.hasPermi('monitor:logininfor:remove')")
	@Log(title = "登陆日志", businessType = BusinessType.DELETE)
	@DeleteMapping("/remove/{infoIds}")
	public Result<Object> remove(@PathVariable Long[] infoIds) {
		return Result.success(logininforService.deleteLogininforByIds(infoIds));
	}

	/**
	 * 清空登录日志
	 * @return
	 */
	@PreAuthorize("@ss.hasPermi('monitor:logininfor:remove')")
	@Log(title = "登陆日志", businessType = BusinessType.CLEAN)
	@DeleteMapping("/clean")
	public Result<Object> clean() {
		logininforService.cleanLogininfor();
		return Result.success("succcess");
	}

}
